<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="mall.demo.mybatis.pojo.ProductInCart" %>
<%@ page import="mall.demo.util.SessionKeyEnum" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>购物车</title>
<link href="css/bootstrap.css" rel="stylesheet">
<script src="js/jquery.js?_=201703042022"></script>
<script src="js/bootstrap.js"></script>
</head>
<%!
double sumUp(List<ProductInCart> productInCart) {
	double sum = 0.0;
	for (ProductInCart pc : productInCart) {
		sum += pc.getPrice() * pc.getAmount();
	}
	return sum;
}
%>
<%
List<ProductInCart> productInCart = (List<ProductInCart>)session.getAttribute(SessionKeyEnum.cart.name());
if(productInCart == null) {
	productInCart = new ArrayList<ProductInCart>();
}
Object obj = session.getAttribute(SessionKeyEnum.userObj.name());
boolean isUserLoggedIn = false;
if(obj != null) {
	isUserLoggedIn = true;
}
%>
<body>
<div class="container">
<jsp:include page="top.jsp"></jsp:include>
<!-- first div move down -->
<p style="height:50px;">&nbsp;</p>
<p>我的购物车:</p>
<div class="row">
<div class="col-md-2">Code</div>
<div class="col-md-2">Name</div>
<div class="col-md-2">Price</div>
<div class="col-md-2">Amount</div>
<div class="col-md-2">总价</div>
<div class="col-md-2"></div>
</div>


<div class="row">
	<% for (ProductInCart product : productInCart) { %>
	<div class="col-md-2"><%=product.getCode() %></div>
		<div class="col-md-2"><%=product.getName() %></div>
		
		<div class="col-md-2"><%=product.getPrice() %></div>
		
		<div class="col-md-2"><%=product.getAmount() %></div>
		<div class="col-md-2"><%=product.getAmount() * product.getPrice() %></div>
		<div class="col-md-2">&nbsp;</div>
	<% } %>
</div>
<% if (!productInCart.isEmpty()) {%>
<div class="row">
	<div class="col-md-12">Total: <%= sumUp(productInCart) %></div>
</div>
<% } %>
<a href="index.jsp">继续购物</a> 
<% if (isUserLoggedIn && !productInCart.isEmpty()) {%>
	<a href="servlet/makeorder.do">确定下单了</a>
<% } %>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>